<?php
class TracuuController extends AppController {
	public $uses = array('ThongKe','ChiTieuThongKe','Tthc','Ketquahanhchinh','Status','Hoso');
	
	public function beforeFilter() {
		$this->Auth->allow('*');
		$this->layout = 'tracuu';
		$this->set("actionName", $this->request->params['action']);
	}
	
	public function index() {
		$this->redirect(array('action' => 'ketquahanhchinh'));
	}
	
	public function ketquahanhchinh($tthcId = null) {
		// debug($this->request->data);
		
		if(empty($tthcId)) {
			$ketquahanhchinhs = $this->Ketquahanhchinh->find("all");
		} else {
			$ketquahanhchinhs = $this->Ketquahanhchinh->find("all", array('conditions' => array('Ketquahanhchinh.tthc_id' => $tthcId)));	
		}
		
		$tthcs = $this->Tthc->find("list", array('fields'=>array('id','ten'),'conditions' => array('activeFlg' => 1)));
		
		$this->set('selectedTthc', $tthcId);
		$this->set("tthcs", $tthcs);
		$this->set("ketquas", $ketquahanhchinhs);
	}
	
	public function hosotondong($tthcId = null) {
		// debug($this->request->data);
		$tthcId = empty($this->request->data)? 1 : $this->request->data['Tracuu']['tthc_id'];
		
		$conditions = array('Hoso.trang_thai' => $this->Status->HS_TON_DONG, 'Hoso.tthc_id' => $tthcId);
		if(empty($tthcId)) $conditions = array('Hoso.trang_thai' => $this->Status->HS_TON_DONG);
		
		$listHosos = $this->Hoso->find("all", array(
			'conditions' => $conditions
		));
		
		$this->set('selectedTthc', $tthcId);
		$this->set('listHosos', $listHosos);
		
		
		$tthcs = $this->Tthc->find("list", array('fields'=>array('id','ten'),'conditions' => array('activeFlg' => 1)));
		$this->set("tthcs", $tthcs);
	}

	public function hskhongdenlayketqua($tthcId = null) {
		// debug($this->request->data);
		$tthcId = empty($this->request->data)? 1 : $this->request->data['Tracuu']['tthc_id'];
		
		$conditions = array('Hoso.trang_thai' => $this->Status->HS_KHONG_DEN_NHAN_KQ, 'Hoso.tthc_id' => $tthcId);
		if(empty($tthcId)) $conditions = array('Hoso.trang_thai' => $this->Status->HS_KHONG_DEN_NHAN_KQ);
		
		$listHosos = $this->Hoso->find("all", array(
			'conditions' => $conditions
		));
		
		
		//set result to view
		$this->set('selectedTthc', $tthcId);
		$this->set('listHosos', $listHosos);
		$tthcs = $this->Tthc->find("list", array('fields'=>array('id','ten'),'conditions' => array('activeFlg' => 1)));
		$this->set("tthcs", $tthcs);
	}
	
	public function danhsachcanhan($tthcId = null) {
		$tthcId = empty($this->request->data)? 1 : $this->request->data['Tracuu']['tthc_id'];
		
		$conditions = array('Ketquahanhchinh.doi_tuong' => 1, 'Ketquahanhchinh.tthc_id' => $tthcId);
		if(empty($tthcId)) $conditions = array('Ketquahanhchinh.doi_tuong' => 1);
		
		$ketquahanhchinhs = $this->Ketquahanhchinh->find("all", array('conditions' => $conditions));	
		
		// set data to view
		$this->set('selectedTthc', $tthcId);
		$this->set('ketquas', $ketquahanhchinhs);
		$tthcs = $this->Tthc->find("list", array('fields'=>array('id','ten'),'conditions' => array('activeFlg' => 1)));
		$this->set("tthcs", $tthcs);
	}
	
	public function danhsachtapthe($tthcId = null) {
		$tthcId = empty($this->request->data)? 1 : $this->request->data['Tracuu']['tthc_id'];
		
		$conditions = array('Ketquahanhchinh.doi_tuong' => 2, 'Ketquahanhchinh.tthc_id' => $tthcId);
		if(empty($tthcId)) $conditions = array('Ketquahanhchinh.doi_tuong' => 2);
		
		$ketquahanhchinhs = $this->Ketquahanhchinh->find("all", array('conditions' => $conditions));	
		
		// set data to view
		$this->set('selectedTthc', $tthcId);
		$this->set('ketquas', $ketquahanhchinhs);
		$tthcs = $this->Tthc->find("list", array('fields'=>array('id','ten'),'conditions' => array('activeFlg' => 1)));
		$this->set("tthcs", $tthcs);
	}
}
	